package com.meiqiongproperty.yiguanjia.fragment.home.yipension;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.activity.GenericFragmentActivity;
import com.meiqiongproperty.yiguanjia.databinding.DailyCareLayoutBinding;
import com.meiqiongproperty.yiguanjia.fragment.BaseFragment;
import com.meiqiongproperty.yiguanjia.fragment.home.adapter.OnItemClickListener;
import com.meiqiongproperty.yiguanjia.fragment.home.adapter.yiPensionAdapter.DailyCareListAdapter;
import com.meiqiongproperty.yiguanjia.fragment.home.life.DailyCleannerFragment;
import com.meiqiongproperty.yiguanjia.http.api.ApiService;
import com.meiqiongproperty.yiguanjia.http.interfaces.IHttpCallback;
import com.meiqiongproperty.yiguanjia.http.sendJsonModel.SendLifeDetail;
import com.meiqiongproperty.yiguanjia.httpbean.life.LifeDetailBean;
import com.meiqiongproperty.yiguanjia.httpbean.pension.DailyCareBean;
import com.meiqiongproperty.yiguanjia.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * author: Administrator
 * date: 2017/5/11.
 * package:com.meiqiongproperty.yiguanjia.fragment.home.yipension
 * 日常照料列表界面
 */

public class DailyCareFragment extends BaseFragment {
    DailyCareLayoutBinding binding;
    List<DailyCareBean> dailyCareList=new ArrayList<>();
    DailyCareListAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding= DataBindingUtil.inflate(inflater, R.layout.daily_care_layout,container,false);
//        initDate();
//
//        adapter.setOnItemClickListener(new OnItemClickListener() {
//            @Override
//            public void onItemClick(View view, int position) {
//                GenericFragmentActivity.start(getActivity(),DailyCareDetailFragment.class,new Bundle());
//            }
//        });
        binding.navigation.setTitle("日常照料");
        binding.navigation.setLeftClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendKeyBackEvent();
            }
        });
        getDailyCareList();
        return binding.getRoot();
    }

    private void initDate(){
        binding.navigation.setTitle("日常照料");
        binding.navigation.setLeftClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendKeyBackEvent();
            }
        });

        for (int i=0;i<5;i++){
            DailyCareBean bean=new DailyCareBean();
            bean.setDailyCareImageId(R.mipmap.title_image);
            bean.setDailyCareTitle("午餐订购（包括早，中，晚餐）");
            bean.setPrice("破盘价只要￥998");
            dailyCareList.add(bean);
        }
    }

    /**
     * 日常照料列表
     */
    public void getDailyCareList(){
        SendLifeDetail send = new SendLifeDetail();
        send.setToken(Utils.getToken(getActivity()));
        send.setCateId("1");
        send.setRoomID(Utils.getRoomID(getActivity()));

        ApiService.getLifeDetailList(getActivity(), new IHttpCallback<LifeDetailBean>() {
            @Override
            public void onNext(final LifeDetailBean lifeDetailBean) {
                LinearLayoutManager manager = new LinearLayoutManager(getActivity());
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                binding.recyclerDailyCare.setLayoutManager(manager);
                adapter=new DailyCareListAdapter(getActivity(),lifeDetailBean.getService());
                binding.recyclerDailyCare.setAdapter(adapter);

                adapter.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        Bundle bundle=new Bundle();
                        bundle.putString("id",lifeDetailBean.getService().get(position).getId());
                        GenericFragmentActivity.start(getActivity(),DailyCleannerFragment.class,bundle);
                    }
                });
            }

            @Override
            public void onError(int code, String message) {

            }
        }, Utils.getRequestBody(send));
    }


}
